﻿using System;

namespace WeatherRetriever
{
    public class Weather
    {
        private ITemperature temperature;
        private ITemperature feelsLike;
        private Wind wind;
        private DateTime date;
        private String condition;
        private byte precip, humidity;

        public Weather()
        {
            precip = 0;
            humidity = 0;
            date = DateTime.Now;
        }

        public ITemperature Temperature
        {
            get { return temperature; }
            set { temperature = value; }
        }

        public ITemperature FeelsLike
        {
            get { return feelsLike; }
            set { feelsLike = value; }
        }

        public Wind WindCondition
        {
            get { return wind; }
            set { wind = value; }
        }

        public DateTime Date
        {
            get { return date; }
            set { date = value; }
        }

        public String Condition
        {
            get { return condition; }
            set { condition = value; }
        }

        public byte Precipitation
        {
            get { return precip; }
            set { precip = value; }
        }

        public byte Humidity
        {
            get { return humidity; }
            set { humidity = value; }
        }

        public class Wind
        {
            public enum Direction
            {
                NONE, N, NNE, NE, ENE, E,
                ESE, SE, SSE, S, SSW,
                SW, WSW, W, WNW, NW, NNW
            }

            private byte speed_mph;
            private Direction direction;

            public Wind(byte mphSpeed, Direction dir)
            {
                speed_mph = mphSpeed;
                direction = dir;
            }

            public byte MPHSpeed
            {
                get { return speed_mph; }
                set { speed_mph = value; }
            }

            public Direction WindDirection
            {
                get { return direction; }
                set { direction = value; }
            }

            public override string ToString()
            {
                return speed_mph.ToString() + " mph " + DirectionToString(direction);
            }

            public static Direction StringToDirection(string st)
            {
                string str = st.ToUpper().Trim();

                if (str.Equals("")) return Direction.NONE;
                else if (str.Equals("N")) return Direction.N;
                else if (str.Equals("NNE")) return Direction.NNE;
                else if (str.Equals("NE")) return Direction.NE;
                else if (str.Equals("ENE")) return Direction.ENE;
                else if (str.Equals("E")) return Direction.E;
                else if (str.Equals("ESE")) return Direction.ESE;
                else if (str.Equals("SE")) return Direction.SE;
                else if (str.Equals("SSE")) return Direction.SSE;
                else if (str.Equals("S")) return Direction.S;
                else if (str.Equals("SSW")) return Direction.SSW;
                else if (str.Equals("SW")) return Direction.SW;
                else if (str.Equals("WSW")) return Direction.WSW;
                else if (str.Equals("W")) return Direction.W;
                else if (str.Equals("WNW")) return Direction.WNW;
                else if (str.Equals("NW")) return Direction.NW;
                else if (str.Equals("NNW")) return Direction.NNW;
                else throw new ArgumentException("Argument is not a valid direction string");
            }

            public static string DirectionToString(Direction dir)
            {
                switch (dir)
                {
                    case Direction.NONE:
                        return "";
                    case Direction.N:
                        return "N";
                    case Direction.NNE:
                        return "NNE";
                    case Direction.NE:
                        return "NE";
                    case Direction.ENE:
                        return "ENE";
                    case Direction.E:
                        return "E";
                    case Direction.ESE:
                        return "ESE";
                    case Direction.SE:
                        return "SE";
                    case Direction.SSE:
                        return "SSE";
                    case Direction.S:
                        return "S";
                    case Direction.SSW:
                        return "SSW";
                    case Direction.SW:
                        return "SW";
                    case Direction.WSW:
                        return "WSW";
                    case Direction.W:
                        return "W";
                    case Direction.WNW:
                        return "WNW";
                    case Direction.NW:
                        return "NW";
                    case Direction.NNW:
                        return "NNW";
                }
                throw new ArgumentException("Argument is invalid");
            }
        }

    }
}
